package com.xxgc.mq.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/addOrder")
    public String addOrder(){
        Map<String, Object> map = new HashMap<>();
        //90%的支付接口，金额单位为分
        map.put("money",new Random().nextInt(1000));//单位：分
        map.put("id", UUID.randomUUID());
        rabbitTemplate.convertAndSend("order_exchange","order",map);
        return "订单创建成功，请及时支付";
    }

}
